package com.fc.controller;


import com.fc.dto.pageQuery.AttendancePageQueryDTO;
import com.fc.result.PageResult;
import com.fc.result.Result;
import com.fc.service.IAttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@Api(tags = "打卡")
@RestController
@RequestMapping("/attendance")
public class AttendanceController {

    @Autowired
    private IAttendanceService attendanceService;

    /**
     * 上班打卡
     *
     * @return
     */
    @ApiOperation("上班打卡")
    @GetMapping("/punchIn")
    public Result punchIn(String location,String vehiclePlate) {
        attendanceService.punchIn(location,vehiclePlate);
        return Result.success();
    }


    /**
     * 下班打卡
     * @return
     */
    @ApiOperation("下班打卡")
    @GetMapping("/punchOut")
    public Result punchOut(String location,String vehiclePlate) {
        attendanceService.punchOut(location,vehiclePlate);
        return Result.success();
    }

    /**
     * 查看自己打卡信息(时间和id)
     *
     * @return
     */
    @ApiOperation("查看自己打卡信息")
    @PostMapping("/list")
    public Result<PageResult> list(@RequestBody AttendancePageQueryDTO attendancePageQueryDTO) {
        PageResult pageResult = attendanceService.listByDriver(attendancePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查看所有的打卡信息
     *
     * @param attendancePageQueryDTO
     * @return
     */
    @PreAuthorize("hasRole('ADMIN')")
    @ApiOperation("查看所有的打卡信息")
    @PostMapping("/page")
    public Result<PageResult> listPage(@RequestBody AttendancePageQueryDTO attendancePageQueryDTO) {
        PageResult pageResult = attendanceService.listPage(attendancePageQueryDTO);
        return Result.success(pageResult);
    }

}
